<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>获取所在省市区</title>
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>

<body>
    <p></p>
    <script charset="utf-8" src="js/qqmap.js"></script>
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=E17196ee6b0851315b7c9503f40060c9&s=1"></script>
    <script>
        var citylocation, map, marker = null;
        var init = function() {
            var myGeo = new BMap.Geocoder();
            //设置城市信息查询服务
            citylocation = new qq.maps.CityService({
                //请求成功回调函数
                complete: function(result) {
                    var pt = new BMap.Point(result.detail.latLng.lng, result.detail.latLng.lat);
                    myGeo.getLocation(pt, function(result) {
                        if (result) {
                            var addComp = result.addressComponents;
                            $("p").html(JSON.stringify(result));
                        }
                    });
                },
                error: function() {
                    alert("出错了，请输入正确的经纬度！！！");
                }
            });
            citylocation.searchLocalCity();
        }
        init();
    </script>

</body>

</html>